<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<title>OO2-首页</title>
		<link href="css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="css/iconfont.css" />
		<style>
			html,
			body {
				background-color: #efeff4;
			}
		</style>

	</head>

	<body>
		<!--<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-pull-left"></a>
			<h1 id="title" class="mui-title">首页</h1>
		</header>-->

		<nav class="mui-bar mui-bar-tab">
			<a id="homepage" class="mui-tab-item mui-active" href="http://172.19.254.70:8080/home">
				<span class="mui-icon mui-icon-home"></span>
				<span class="mui-tab-label">首页</span>
			</a>
			<a id="shoppage" class="mui-tab-item" href="http://172.19.254.70:8080/shop">
				<span class="mui-icon iconfont icon-shop"></span>
				<span class="mui-tab-label">店铺</span>
			</a>
			<a id="shopcarpage" class="mui-tab-item" href="http://172.19.254.70:8080/shopcar">
				<span class="mui-icon iconfont icon-shop1"></span>
				<span class="mui-tab-label">购物车</span>
			</a>
			<a id="bookpage" class="mui-tab-item" href="http://172.19.254.70:8080/book">
				<span class="mui-icon mui-icon-list"></span>
				<span class="mui-tab-label">订单</span>
			</a>
			<a id="settingpage" class="mui-tab-item" href="http://172.19.254.70:8080/setting">
				<span class="mui-icon mui-icon-contact"></span>
				<span class="mui-tab-label">我的</span>
			</a>
		</nav>

		<script src="js/mui.min.js"></script>
		<script src="js/app.js"></script>
		<script type="text/javascript" charset="UTF-8">
			mui.init();
			var subpages = ['http://172.19.254.70:8080/home', 'http://172.19.254.70:8080/shop', 'http://172.19.254.70:8080/shopcar',
				'http://172.19.254.70:8080/book', 'http://172.19.254.70:8080/setting'
			];
			var subpagesid = ['homepage', 'shoppage', 'shopcarpage', 'bookpage', 'settingpage'];
			var subpage_style = {
				top: '0px',
				bottom: '51px'
			};
			var aniShow = {};
			//创建子页面，首页显示，其他隐藏
			mui.plusReady(function() {
				var self = plus.webview.currentWebview();
				plus.webview.getWebviewById()
				for (var i = 0; i < subpages.length; i++) {
					var temp = {};
					var sub = plus.webview.create(subpages[i], subpagesid[i], subpage_style);
					if (i > 0) {
						sub.hide();
					} else {
						temp[subpagesid[i]] = "true";
						mui.extend(aniShow, temp);
					}
					self.append(sub);
				}
			});
			//当前激活选项
			var firstActive = 0;
			var activeTab = subpagesid[firstActive];
			var needReload = true;
			mui('.mui-bar-tab').on('tap', 'a', function(e) {
				var targetTab = this.id;
				if (targetTab == activeTab) {
					return;
				}
				//	title.innerHTML = this.querySelector('.mui-tab-label').innerHTML;
				//显示目标选项卡
				//若为ios平台或非首次显示，则直接显示
				if (mui.os.ios || aniShow[targetTab]) {
					plus.webview.show(targetTab);
					if (targetTab == "shopcarpage") {
						plus.webview.getWebviewById(targetTab).reload(true);
					}
					if (targetTab == "bookpage") {
						plus.webview.getWebviewById(targetTab).reload(true);
					}
					if (targetTab == "settingpage" && needReload) {
						plus.webview.getWebviewById(targetTab).reload(true);
						needReload = false;
					}
				} else {
					var temp = {};
					temp[targetTab] = "true";
					mui.extend(aniShow, temp);
					plus.webview.show(targetTab, "fade-in", 300);
				}
				plus.webview.hide(activeTab);
				activeTab = targetTab;
			});

			//自定义事件，模拟点击“首页选项卡”
			document.addEventListener('gohome', function() {
				var homeTab = document.getElementById("homepage");
				//模拟首页点击
				mui.trigger(homeTab, 'tap');
				//切换选项卡高亮
				var current = document.querySelector(".mui-bar-tab>.mui-tab-item.mui-active");
				if (homeTab !== current) {
					current.classList.remove('mui-active');
					homeTab.classList.add('mui-active');
				}
				needReload = true;
			});

		</script>
	</body>

</html>